﻿using oceanho.webapi.factory.httpEntity;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace oceanho.webapi.factory.httpCore.ReqKernal
{
    /// <summary>
    /// 定义一个类，该类实现了IReqCacheFactory接口，用于默认对请求对象ReqCache的管理实现
    /// </summary>
    public class DefaultReqCacheDb : IReqCacheDb
    {
        /// <summary>
        /// 
        /// </summary>
        /// <param name="request"></param>
        /// <returns></returns>
        public ReqCache Get(System.Web.HttpRequest request)
        {
            return DefaultReqCacheDbKernal.Get(request);
        }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="key"></param>
        /// <param name="isCached"></param>
        /// <returns></returns>
        public ReqCache Get(string key, out bool isCached)
        {
            return DefaultReqCacheDbKernal.Get(key, out isCached);
        }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="key"></param>
        /// <returns></returns>
        public ReqCache GetReqCache(string key)
        {
            return DefaultReqCacheDbKernal.GetReqCache(key);
        }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="request"></param>
        /// <param name="key"></param>
        /// <param name="reqCache"></param>
        /// <param name="isCached"></param>
        /// <param name="isForever"></param>
        /// <returns></returns>
        public bool Set(System.Web.HttpRequest request, string key, ReqCache reqCache, bool isCached, bool isForever)
        {
            return DefaultReqCacheDbKernal.Set(request, key, reqCache, isCached, isForever);
        }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="reqCache"></param>
        /// <param name="isForce"></param>
        public void RemoveBadIP(ref ReqCache reqCache, bool isForce = false)
        {
            DefaultReqCacheDbKernal.RemoveBadIP(ref reqCache, isForce);
        }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="reqCache"></param>
        public void SetBadIPForever(ref ReqCache reqCache)
        {
            DefaultReqCacheDbKernal.RemoveBadIP(ref reqCache);
        }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="reqCache"></param>
        public void SetIsValidIPForever(ref ReqCache reqCache)
        {
            DefaultReqCacheDbKernal.SetIsValidIPForever(ref reqCache);
        }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="reqCache"></param>
        /// <param name="addNum"></param>
        public void AddReq_Wait_Count(ref ReqCache reqCache, int addNum)
        {
            DefaultReqCacheDbKernal.AddReq_Wait_Count(ref reqCache, addNum);
        }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="reqCache"></param>
        /// <param name="addNum"></param>
        public void AddReq_Seconds_Count(ref ReqCache reqCache, int addNum)
        {
            DefaultReqCacheDbKernal.AddReq_Seconds_Count(ref reqCache, addNum);
        }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="reqCache"></param>
        /// <returns></returns>
        public bool IsValidIP(ReqCache reqCache)
        {
            return DefaultReqCacheDbKernal.IsValidIP(reqCache);
        }

        /// <summary>
        /// 
        /// </summary>
        public void ClearReqCache()
        {
            DefaultReqCacheDbKernal.ClearReqCache();
        }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="reqKey"></param>
        public bool Remove(string reqKey)
        {
            return DefaultReqCacheDbKernal.Remove(reqKey);
        }
    }
}
